{{!

  Copyright (c) Meta Platforms, Inc. and affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}// BEGIN declare_enums
{{#program:enums?}}
namespace {{program:qualified_namespace}} {
{{#program:enums}}

{{> common/enum_docblock }}
enum {{^enum:cpp_is_unscoped}}class {{/enum:cpp_is_unscoped}}{{enum:cpp_name}}{{#enum:cpp_enum_type}} : {{enum:cpp_enum_type}}{{/enum:cpp_enum_type}} {
{{#enum:values}}
  {{enum_value:cpp_name}} = {{enum_value:value}},
{{/enum:values}}
};
{{#enum:cpp_declare_bitwise_ops}}
{{> module_types_h/enum_bitwise_ops}}
{{/enum:cpp_declare_bitwise_ops}}
{{/program:enums}}

} // namespace {{program:qualified_namespace}}

{{#program:enums}}
template<> struct std::hash<::{{program:qualified_namespace}}::{{enum:cpp_name}}> :
  ::apache::thrift::detail::enum_hash<::{{program:qualified_namespace}}::{{enum:cpp_name}}> {};
{{/program:enums}}

namespace apache::thrift {
{{#program:enums}}

template <> struct TEnumTraits<::{{program:qualified_namespace}}::{{enum:cpp_name}}> {
  using type = ::{{program:qualified_namespace}}::{{enum:cpp_name}};

  static constexpr std::size_t const size = {{(array.len enum:values)}};
  static folly::Range<type const*> const values;
  static folly::Range<std::string_view const*> const names;
  static const std::string_view __fbthrift_module_name_internal_do_not_use;

  static bool findName(type value, std::string_view* out) noexcept;
  static bool findValue(std::string_view name, type* out) noexcept;

  FOLLY_ERASE static std::string_view typeName() noexcept {
    return "{{enum:name}}";
  }

  FOLLY_ERASE static constexpr std::string_view moduleName() noexcept {
    return "{{program:name}}";
  }

  {{#enum:uri}}
  FOLLY_ERASE static constexpr std::string_view __fbthrift_thrift_uri() noexcept {
    return "{{enum:uri}}";
  }

  {{/enum:uri}}
  static char const* findName(type value) noexcept {
    std::string_view ret;
    (void)findName(value, &ret);
    return ret.data();
  }
  {{#if (not (array.empty? enum:values))}}
  static constexpr type min() { return type::{{enum:cpp_min}}; }
  static constexpr type max() { return type::{{enum:cpp_max}}; }
  {{/if (not (array.empty? enum:values))}}
};
{{/program:enums}}

} // namespace apache::thrift
{{/program:enums?}}
// END declare_enums
